<template>
    <div class="app-container">
        <div id="selected_course_list">
            <el-tag v-if="selectedCourse.title" closable size="medium" :disable-transitions="false"
                @close="handleClose()">
                <div>
                    <el-card class="box-card">
                        <el-avatar :size="40" :src="selectedCourse.cover"></el-avatar>
                        {{ selectedCourse.title }}
                    </el-card>
                </div>
            </el-tag>

            <el-button type="primary" icon="el-icon-plus" circle v-if="!show_course_table && !selectedCourse.title"
                @click="show_course_table = true"></el-button>
        </div>

        <div id="course_table" v-if="show_course_table">
            <el-card class="box-card">
                <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
                    <el-form-item label="标题" prop="title">
                        <el-input v-model="queryParams.title" placeholder="请输入标题" clearable size="small"
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item label="简介" prop="about">
                        <el-input v-model="queryParams.about" placeholder="请输入简介" clearable size="small"
                            @keyup.enter.native="handleQuery" />
                    </el-form-item>

                    <el-form-item label="是否免费" prop="isFree">
                        <el-select v-model="queryParams.isFree" placeholder="是否免费" clearable size="small">
                            <el-option v-for="dict in isFreeOptions" :key="dict.dictValue" :label="dict.dictLabel"
                                :value="dict.dictValue" />
                        </el-select>
                    </el-form-item>

                    <el-form-item label="状态" prop="status">
                        <el-select v-model="queryParams.status" placeholder="课程状态" clearable size="small">
                            <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel"
                                :value="dict.dictValue" />
                        </el-select>
                    </el-form-item>

                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-form>

                <el-table v-loading="loading" :data="educourseList" @selection-change="handleSelectionChange">
                    >
                    <el-table-column type="selection" width="55" align="center" />
                    <el-table-column label="课程封面" align="center" prop="cover" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <el-avatar :size="50" :src="scope.row.cover"></el-avatar>
                        </template>
                    </el-table-column>
                    <el-table-column label="标题" align="center" prop="title" :show-overflow-tooltip="true" />

                    <el-table-column label="简介" align="center" prop="about" :show-overflow-tooltip="true" />
                    <el-table-column label="点击量" align="center" prop="hitNum" :show-overflow-tooltip="true" />
                    <el-table-column label="是否免费" align="center" prop="isFree" :formatter="isFreeFormat" width="100">
                        <template slot-scope="scope">
                            {{ isFreeFormat(scope.row) }}
                        </template>
                    </el-table-column>
                    <el-table-column label="原价" align="center" prop="originPrice" :show-overflow-tooltip="true" />
                    <el-table-column label="现价" align="center" prop="price" :show-overflow-tooltip="true" />
                    <el-table-column label="vip价" align="center" prop="vipPrice" :show-overflow-tooltip="true" />

                    <el-table-column label="连载方式" align="center" prop="serializeMode" :formatter="serializeModeFormat"
                        width="100">
                        <template slot-scope="scope">
                            {{ serializeModeFormat(scope.row) }}
                        </template>
                    </el-table-column>
                    <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" width="100">
                        <template slot-scope="scope">
                            {{ statusFormat(scope.row) }}
                        </template>
                    </el-table-column>

                    <el-table-column label="课时总数" align="center" prop="lessonNum" :show-overflow-tooltip="true" />
                    <el-table-column label="课程状态" align="center" prop="locked" :formatter="lockedFormat" width="100">
                        <template slot-scope="scope">
                            {{ lockedFormat(scope.row) }}
                        </template>
                    </el-table-column>
                    <el-table-column label="笔记数" align="center" prop="noteNum" :show-overflow-tooltip="true" />
                    <el-table-column label="课时发布数量" align="center" prop="publishLessonNum"
                        :show-overflow-tooltip="true" />
                    <el-table-column label="问题数" align="center" prop="questionNum" :show-overflow-tooltip="true" />
                    <el-table-column label="课程计划评分" align="center" prop="rating" :show-overflow-tooltip="true" />
                    <el-table-column label="课程计划评论数" align="center" prop="ratingNum" :show-overflow-tooltip="true" />
                    <el-table-column label="学员数" align="center" prop="studentNum" :show-overflow-tooltip="true" />
                    <el-table-column label="话题数" align="center" prop="threadNum" :show-overflow-tooltip="true" />
                </el-table>

                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageIndex"
                    :limit.sync="queryParams.pageSize" @pagination="getList" />
            </el-card>
        </div>
    </div>
</template>


<style lang="scss" scoped>
// .el-tag--medium {
//     height: 116px;
//     line-height: 42px;
// }

.el-tag .el-icon-close {
    border-radius: 50%;
    text-align: center;
    position: relative;
    cursor: pointer;
    font-size: 30px;
    height: 16px;
    width: 16px;
    line-height: 30px;
    vertical-align: middle;
    top: -116px;
    right: -161px;
}

.dialogForm {
    display: block;
    .el-dialog {
        margin-top: 15vh !important;
    }
}
.flip-list-move {
    transition: transform 0.5s;
}

.no-move {
    transition: transform 0s;
}

.ghost {
    opacity: 0.1;
    background: #eee;
}

.list-group {
    min-height: 20px;
    border-left: 2px solid #f1f1f1 !important;
}
.line {
    height: 2px;
    background: #fafafa;
    -webkit-user-select: none; /* 禁止 DIV 中的文本被鼠标选中 */
    -moz-user-select: none; /* 禁止 DIV 中的文本被鼠标选中 */
    -ms-user-select: none; /* 禁止 DIV 中的文本被鼠标选中 */
    user-select: none;
}

.list-group-item {
    cursor: move;
    padding: 0 24px;
    width: 100%;
    height: 56px;
    line-height: 56px;
    background: #fafafa !important;
    border-radius: 6px;
}
.list-group-item i {
    cursor: pointer;
}
.wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
}
.item {
    width: 300px;
    height: 50px;
    background-color: #42b983;
    color: #ffffff;
}
.content {
    padding: 0 20px;
    .courseBox {
        padding: 20px;
        border-radius: 6px;
        border: 1px solid #ddd;
    }
}
.taskBox {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    width: 95%;
    box-sizing: border-box;
}
.freeTask {
    color: #fff;
    background-color: #f46300;
}
.taskItem .el-checkbox__label {
    width: 100%;
}
.el-dropdown-link {
    cursor: pointer;
    color: #409eff;
    font-size: 12px;
    margin-left: 10px;
}
.el-icon-arrow-down {
    font-size: 12px;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader .el-upload:hover {
    border-color: #409eff;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}
.avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>
<script>
import { listEduCourse } from "@/api/edu/service";

import { getToken } from "@/utils/auth";
export default {
    name: "Config",
    components: {},

    data () {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 总条数
            total: 0,
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            isEdit: false,
            // 类型数据字典
            typeOptions: [],
            educourseList: [],
            isFreeOptions: [],
            lockedOptions: [],
            serializeModeOptions: [],
            statusOptions: [],
            // 查询参数
            queryParams: {
                pageIndex: 1,
                pageSize: 5,
                about: undefined,
                courseId: undefined,
                isFree: undefined,
                locked: undefined,
                originPrice: undefined,
                status: undefined,
                title: undefined,
            },

            //选中的课程
            selectedCourse: {},
            //是否显示table
            show_course_table: false,
        };
    },
    created () {
        this.selectedCourse = {};
        // if (this.$route.params.name) {
        this.$store.dispatch("tagsView/updateVisitedView", this.$route);
        // }
        console.log(this.$route);
        this.schoolId = this.$route.params.schoolId;
        this.getList();
        this.getDicts("sys_bool").then((response) => {
            this.isFreeOptions = response.data;
        });

        this.getDicts("sys_bool").then((response) => {
            this.lockedOptions = response.data;
        });

        this.getDicts("edu_serialize_mode").then((response) => {
            this.serializeModeOptions = response.data;
        });

        this.getDicts("edu_status").then((response) => {
            this.statusOptions = response.data;
        });
    },
    methods: {
        /** 查询参数列表 */
        getList () {
            this.loading = true;
            if (this.schoolId) {
                schoolCourseList(
                    this.schoolId,
                    this.addDateRange(this.queryParams, this.dateRange)
                ).then((response) => {
                    this.educourseList = response.data.list;
                    this.total = response.data.count;
                    this.loading = false;
                });
            } else {
                listEduCourse(this.addDateRange(this.queryParams, this.dateRange)).then(
                    (response) => {
                        this.educourseList = response.data.list;
                        this.total = response.data.count;
                        this.loading = false;
                    }
                );
            }
        },

        isFreeFormat (row) {
            return this.selectDictLabel(this.isFreeOptions, row.isFree);
        },
        lockedFormat (row) {
            return this.selectDictLabel(this.lockedOptions, row.locked);
        },
        serializeModeFormat (row) {
            return this.selectDictLabel(this.serializeModeOptions, row.serializeMode);
        },
        statusFormat (row) {
            return this.selectDictLabel(this.statusOptions, row.status);
        },

        /** 搜索按钮操作 */
        handleQuery () {
            this.queryParams.pageIndex = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery () {
            this.dateRange = [];
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange (selection) {
            console.log(selection[0]);
            this.selectedCourse = selection[0];
            this.show_course_table = false;
            //传给父组件
            this.$emit("setCourseId", this.selectedCourse.courseId);
        },

        handleClose (tag) {
            this.selectedCourse = {};
            this.show_course_table = true;
            //传给父组件
            this.$emit("setCourseId", 0);
        },
    },
};
</script>
